<?php

namespace App\Orchid\Layouts\Setting;

use Orchid\Screen\Field;
use Orchid\Screen\Fields\Input;
use Orchid\Screen\Fields\Select;
use Orchid\Screen\Layouts\Rows;

class SettingFiltersLayout extends Rows
{
    /**
     * Used to create the title of a group of form elements.
     *
     * @var string|null
     */
    protected $title = '筛选器';

    /**
     * Get the fields elements to be displayed.
     *
     * @return Field[]
     */
    protected function fields(): iterable
    {
        return [
            Input::make('filter[key]')
                ->type('text')
                ->value($this->query->get('filter.key'))
                ->placeholder('按设置键搜索')
                ->title('设置键'),

            Input::make('filter[name]')
                ->type('text')
                ->value($this->query->get('filter.name'))
                ->placeholder('按设置名称搜索')
                ->title('设置名称'),

            Select::make('filter[type]')
                ->options([
                    '' => '所有类型',
                    'text' => '文本',
                    'textarea' => '多行文本',
                    'number' => '数字',
                    'boolean' => '布尔值',
                    'select' => '选择',
                    'json' => 'JSON',
                ])
                ->value($this->query->get('filter.type'))
                ->title('类型'),

            Input::make('filter[group]')
                ->type('text')
                ->value($this->query->get('filter.group'))
                ->placeholder('按分组搜索')
                ->title('分组'),
        ];
    }
}